<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>注册</title>
<%@ include file="/pages/wx/baseHead.jsp"%>
<link rel="stylesheet" href="<%=basePath%>/css/weixin/example.css" />
<script type="text/javascript">
	$(function(){
		var user = '${user}';
		if(user.length>0)
		{
			//location.href = '${urlBasePath}weixin/index.do';
		}
		
		setReadOnly("#checkCode",true);
		setDisable(".checkCodeClass",true);
		
		
		$("#phone").bind('input',function(){
			if(isValidPhone())
			{
				setDisable(".checkCodeClass",false);
				$(".checkCodeClass").bind( "click",function(){
					sendCode();
				});
			}else
			{
				setDisable(".checkCodeClass",true);
				$(".checkCodeClass").unbind( "click");
			}
		});
	});
	
	var times = 120;
	function cd()
	{
		if(times == 0)//释放
		{
			$("#getCodeFont").html("获取验证码");
			setDisable(".checkCodeClass",false);
			setReadOnly("#phone",false);
			
			$(".checkCodeClass").bind( "click",function(){
				sendCode();
			});
			return;
		}
		times--;
		$("#getCodeFont").html(times+"秒后重取");
		setTimeout("cd();",1000);
	}
	
	
	function sendCode()
	{
		var phone = $("#phone").val();
		var url = '${urlBasePath}weixin/sendCodeReg.do';
		loading('正在发送');
		$.ajax({
			type: 'POST',
			url:url,
			async:false,
			data:
			{
				phone:phone,
				v:new Date().getTime()
			},
			success:function(data)
			{
				unLoading();
				if(data.code == '0')
				{
					times = 120;
					setDisable(".checkCodeClass",true);
					$(".checkCodeClass").unbind( "click");
					cd();
					setReadOnly("#phone",true);
					setReadOnly("#checkCode",false);
					
					openToast("验证码已发送");
				}else
				{
					openDia("提示",data.msg);
				}
			},
			fail:function()
			{
				unLoading();
				openToast('发送验证码失败');
			}
		});
		
		
	}
	
	function check()
	{
		var name = $("#name").val();
		var phone = $("#phone").val();
		var checkCode = $("#checkCode").val();
		var regu =/^[\u4e00-\u9fa5]*$/;
		var re = new RegExp(regu);
		debugger;
		if(name == '' || !re.test(name))
		{
			openDia(null,"请认真填写名字");
			return false;
		}
		if(phone == null || phone == '')
		{
			openDia(null,"请填写手机");
			return false;
		}
		if(checkCode == null || checkCode == '')
		{
			openDia(null,"请填写验证码");
			return false;
		}
		return true;
	}
	
	function reg()
	{
		if(!check())
		{
			return;
		}
		
		var phone = $("#phone").val();
		var checkCode = $("#checkCode").val();
		var url = '${urlBasePath}weixin/isValidCode.do';
		$.ajax({
			url:url,
			async:false,
			data:{
				phone:phone,
				checkCode:checkCode,
				funcCode:'1001'
			},
			success:function(ret){
				if(ret.code == '0')
				{
					$('#token').val(new Date().getTime());
					loading('正在注册...');
					$("#theform").submit();
				}else
				{
					openDia(ret.msg);
				}
			},
			error:function(){
				
			}
		})
		
	}
	
	
	
</script>

</head>
<body>

<div class="hd">
    <h1 class="page_title">注册成为会员</h1>
</div>
<form action="${urlBasePath}weixin/reg.do" method="POST" name = "theform" id="theform">
<div class="hd">

    <div class="weui_cells_title">请填写注册信息</div>
    <div class="weui_cells weui_cells_form">
    
        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label" style="font-weight: normal;min-width: 4em;">姓名：</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" type="text" placeholder="建议您输入真实姓名" id="name" name="name" maxlength="12"/>
                <input class="weui_input" type="hidden" id="token" name="vv"/>
            </div>
        </div>
        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label" style="font-weight: normal;min-width: 4em;">手机号：</label></div>
            <div class="weui_cell_bd weui_cell_primary" >
                <input class="weui_input" type="tel" id="phone" value="" name="phone" pattern="[0-9]*" placeholder="请输入您的手机号"/>
            </div>
            <div class="weui_cell_hd">
            	<span style="margin-left: 1em;" class="weui_btn weui_btn_plain_primary weui_btn_mini checkCodeClass ">
            		<font id="getCodeFont">获取验证码</font>
            	</span>
            </div>
        </div>
        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label"  style="font-weight: normal;min-width: 4em;">验证码：</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" type="number" name="checkCode" id="checkCode" maxlength="4" placeholder="请输入验证码"/>
            </div>
        </div>
        
    </div>
</div>
</form>
<a href="javascript:viod(0);" onclick="reg();" class="weui_btn weui_btn_primary">绑定手机号</a> 


<div class="pop">
    <i class="fa fa-home fa-lg popi"></i>
</div>

<!-- 引入微信样式代码提示工具开始 -->
<%@ include file="/pages/wx/wxClass.jsp"%>
<!-- 引入微信样式代码提示工具结束 -->
<%@ include file="/pages/wx/baseBottom.jsp"%>
</body>
</html>

